package cn.study.jmm;


/**
 * @Author     ：跟大佳一起学
 * @Description：原子性
 */
public class AtomicTest {
    private static volatile int counter = 0;
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                // 10个线程每个线程运行一亿次的结果：104 238 804
                for (int j = 0; j < 10_000_000; j++) {
                    synchronized (AtomicTest.class) {
                        counter++;
                    }
                }
            });
            thread.start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //思考counter=？
        System.out.println(counter);
    }
}










